﻿Imports IICModel.ConversionObjects
Imports IICModel.BusObjects.Mappers
Imports IICModel.ConversionObjects.Mappers
Imports IICModel.BusObjects

Namespace DataConbversionLogic
    ''' <summary>
    ''' import exceptions ie records in old table [CAND_SUB] where status='C'
    ''' </summary>
    ''' <remarks></remarks>
    Public Class PASExceptionsConverter
        Inherits BaseDataConverter

        Protected Overrides Sub mapData(ByVal source As org.model.lib.Model.IModelObject, _
                                        ByRef destination As org.model.lib.Model.IModelObject)

            Dim s As CAND_SUB = CType(source, [CAND_SUB])
            Dim d As StudentLessonCredit = CType(destination, StudentLessonCredit)

            If s.ExamPeriod IsNot Nothing Then
                Me.logMsg(s.Id & " skipped, ExamPeriod is not null")
                destination = Nothing
                Exit Sub
            End If

            Dim llesson As Lesson = LessonsCache.current.getLessonByCode(Trim(s.SUBJECT))
            Dim mstudent As Student = StudentDataUtils.findOne("memberNumber={0}", s.MemberNo)

            If llesson Is Nothing Then
                Me.logMsg(s.Id & " skipped, Lesson not found from code " & s.SUBJECT)
                destination = Nothing
                Exit Sub
            End If

            If mstudent Is Nothing Then
                Me.logMsg(s.Id & " skipped, mstudent not found from code " & s.MemberNo)
                destination = Nothing
                Exit Sub
            End If
            Dim ex As StudentLessonCredit = StudentLessonCreditDataUtils.findOne("LessonId={0} and StudentId={1}", llesson.LessonId, mstudent.StudentId)
            If ex IsNot Nothing Then
                'Me.logMsg(s.Id & " skipped, mstudent not found from code " & s.MemberNo)
                destination = Nothing
                Exit Sub
            End If

            d.LessonId = llesson.LessonId
            d.StudentId = mstudent.StudentId
            d.Comments = "data conversion"

        End Sub

        Protected Overrides Function getTableName() As String
            Return "CAND_SUB"
        End Function

        Protected Overrides Sub instantiateMappers()

            Me.dataConvMapper = New CAND_SUBDBMapper()
            Me.newdbMapper = New StudentLessonCreditDBMapper

        End Sub

        Protected Overrides Function checkData(ByVal source As IModelObject, _
                                  ByVal destination As IModelObject) As Boolean

            Return True
        End Function



    End Class
End Namespace
